package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description NursingLevelController
 * @Author hu hanSan
 * @Date 2024-09-09
 */
@Slf4j
@RestController
@Api(tags = "护理等级的接口")
@RequestMapping("/nursingLevel")
public class NursingLevelController extends BaseController {
    @Autowired
    private NursingLevelService nursingLevelService;

    @GetMapping("/listAll")
    @ApiOperation(value = "查询所有护理等级")
    public ResponseResult<List<NursingLevelVo>> getListAll(){
        List<NursingLevelVo>list = nursingLevelService.getListAll();
        return success(list);
    }

    @ApiOperation(value = "新增护理等级")
    @PostMapping("/insert")
    public ResponseResult addLevel(
            @ApiParam(value = "护理项目数据传输对象", required = true)
            @RequestBody NursingLevelDto nursingLevelDto){
         nursingLevelService.addLevel(nursingLevelDto);
         return success();
    }

    @ApiOperation(value = "分页查询")
    @GetMapping("/listByPage")
    public ResponseResult<PageResponse<NursingLevelVo>> page(
            @ApiParam(value = "护理项目名称")
            @RequestParam(value = "name", required = false) String name,
            @ApiParam(value = "状态：0-禁用，1-启用")
            @RequestParam(value = "status", required = false) Integer status,
            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量")
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize){

        PageResponse<NursingLevelVo> pageResponse= nursingLevelService.page(name,status,pageNum,pageSize);
        return success(pageResponse);
    }

    @ApiOperation(value = "根据id来查询")
    @GetMapping("/{id}")
    public ResponseResult<NursingLevelVo> getById(@PathVariable Long id){
        NursingLevelVo nursingLevelVo=nursingLevelService.getById(id);
        return success(nursingLevelVo);
    }

    @ApiOperation(value = "启用和禁用")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult putStatus(@PathVariable Long id,@PathVariable Integer status){
        nursingLevelService.putStatus(id,status);
        return success();
    }

    @ApiOperation(value = "根据id来删除")
    @DeleteMapping("/delete/{id}")
    public ResponseResult deleteById(@PathVariable Integer id){
        nursingLevelService.deleteById(id);
        return success();
    }

    @ApiOperation(value = "修改护理等级")
    @PutMapping("/update")
    public ResponseResult update(@RequestBody NursingLevelDto nursingLevelDto){
        nursingLevelService.update(nursingLevelDto);
        return success();
    }
}
